﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Black_Jack_Basic_Strategy
{
    class Player
    {
        public bool IsDealer { get; set; }      //For future use.
        public List<Card> m_Hand { get; set; }

        public Player()
        {
            m_Hand = new List<Card>();
        }

        public String GetHandString()
        { 
            //If IsDealer, just show the first card:
            if (IsDealer)
                return m_Hand[0].Value.ToString();
            else
            { 
                String RetString = "";
                for (int i = 0; i < m_Hand.Count; i++)
                {
                    RetString = RetString + m_Hand[i].Value.ToString() + ",";
                }

                RetString = RetString.TrimEnd(',');
                return RetString;
            }
        }

        public String GetPlayerHandDBValue()
        {
            int CardValue0 = m_Hand[0].GetCardValue(0);
            int CardValue1 = m_Hand[1].GetCardValue(CardValue0);        //This will take care of two aces.

            //Change this to reflect the chart better, just a total for 3-21 unless there is an ace or split possible.
            //If there is an ace in the hand, return 'A , X' where x is the card value.
            if (m_Hand[0].IsAce || m_Hand[1].IsAce)
            {
                if (m_Hand[0].IsAce && m_Hand[1].IsAce)
                    return "A , A";
                if (m_Hand[0].IsAce)
                    return "A , " + CardValue1.ToString();
                else
                    return "A , " + CardValue0.ToString();
            }

            //Now take care of splits (no aces):
            if (CardValue0 == CardValue1)
                return CardValue0 + " , " + CardValue1;     //The same, no need to order them.

            //Now, just get the total of the two cards:
            return (CardValue0 + CardValue1).ToString();
        }

        public String GetDealerHandDBValue()
        {
            string s1 = ""; //The first card, should be lower or equal to the second card.
            int CardValue0 = m_Hand[0].GetCardValue(0);
            s1 = CardValue0.ToString();

            if (s1 == "1" || s1 == "11")
                s1 = "A";
            return s1;
        }


        public int GetHandTotal()
        {
            int iRet = 0;
            for (int i = 0; i < m_Hand.Count; i++)
            {
                iRet = iRet + m_Hand[i].GetCardValue(iRet);
            }
            return iRet;
        }

        public int GetShownTotal()
        {
            if (this.IsDealer)
                return this.m_Hand[0].GetCardValue(0);
            else
                return GetHandTotal();
        }

    }
}
